<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>养老院管理系统</title>
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/static/easyui/themes/default/easyui.css">
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath }/static/easyui/themes/icon.css">
<script type="text/javascript" src="${pageContext.request.contextPath }/static/easyui/jquery.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath }/static/easyui/jquery.easyui.min.js"></script>
<script type="text/javascript" src="${pageContext.request.contextPath }/static/easyui/locale/easyui-lang-zh_CN.js"></script>
<style type="text/css">
.title{
	font-size: 50px;
	color: red;
}
.content{
	font-size: 20px;
}
.logo1{
	color: blue;
	font-size: 28px;
	font-weight: bold;
	white-space: nowrap;
	font-style:italic;
	word-break: break-all;
	overflow: hidden;
	-moz-user-select: none;
	font-family:"STFangsong" ;
}
</style>
<script type="text/javascript" language="Javascript">
	$(function(){
		$("#tree").tree({
			lines: true,
			method:'GET',
			url:'${pageContext.request.contextPath }/menu?parentId=-1',
			onLoadSuccess:function() {
				$("#tree").tree('expandAll') ; 
			},
			onClick:function(node){
				if(node.id == 16) {
					$.messager.confirm("系统提示","您确定要登出吗",function(r){
						if(r){
							window.location.href="${pageContext.request.contextPath }/logout" ;
						}
					}) ;
				} else if(node.id == 15) {
					openPasswordDialog() ;
				} else {
					if(node.attributes){
						openTab(node);					
					}					
				}
			}
		}) ;
		
		$("#submitBtn").click(function(){
			var flag = vaild() ;
			var username = $("#username").val() ;
			var password = $("#password").val() ;
			var newPassword = $("#newPassword").val() ;
			var confirmPassword = $("#confirmPassword").val() ;
			if(flag) {
				$.ajax({
					url:'${pageContext.request.contextPath }/updatePassword',
					type:'POST',
					data:{
						username:username,
						password:password,
						newPassword:newPassword
					},
					success:function(data) {
						$.messager.alert("系统提示",data.data) ;
						$("#dlg").dialog("close") ;
						$("#password").val("") ;
						$("#newPassword").val("") ;
						$("#confirmPassword").val("") ;
					}
				}) ;
			}
			return false ;
		}) ;
	}) ;
	function openTab(node) {
		if($("#tabs").tabs("exists",node.text)){
			$("#tabs").tabs("select",node.text)
		} else {
			var content = "<iframe frameborder=0 scrolling='auto' style='width: 100%;height: 100%;' src='" + node.attributes +"'></iframe>"
			$("#tabs").tabs("add",{
				title:node.text,
				closable:true,
				iconCls:node.iconCls,
				content:content
			}) ;
		}
	}
	
	function openPasswordDialog(){
		$("#dlg").dialog("open").dialog("setTitle","修改密码")
	}
	
	function vaild() {
		var flag = true ;
		var password = $("#password").val() ;
		var newPassword = $("#newPassword").val() ;
		var confirmPassword = $("#confirmPassword").val() ;
		
		if(password == null || password == "") {
			alert("密码不能为空") ;
			flag = false ;
		}
		
		if(newPassword == null || newPassword == "") {
			alert("新密码不能为空") ;
			flag = false ;
		} else {
			if(newPassword != confirmPassword) {
				alert("两次密码不一致") ;
				flag = false ;
			}
		}
		
		return flag ;
	}
</script>
</head>
<body class="easyui-layout">
	<!-- header -->
	<div region="north" style="height: 68px;">
		<div style="padding: 0px;margin: 0px;background-color: #E0ECFF;">
			<table>
				<tr>
					<td>
						<img src="${pageContext.request.contextPath }/static/images/logo1.png" style="height: 65px;"/>
					</td>
					<td>
						<span class="logo1">养老院管理系统</span>
					</td>
					<td valign="bottom">欢迎:${user.username }&nbsp;[${user.rolename }]</td>
				</tr>
			</table>
		</div>
	</div>
	<!-- 主信息 -->
	<div region="center">
		<div class="easyui-tabs" fit="true" border="false" id="tabs">
			<div title="首页" data-options="iconCls:'icon-home'">
				<div align="center" style="margin-top: 50px;margin-bottom: 30px;">
					<span class="title">欢迎使用</span>
				</div>
				<!-- <div align="center">
					<span class="content">基于SSM框架的权限管理系统</span>
				</div> -->
			</div>
		</div>
	</div>
	<!-- 导航栏 -->
	<div region="west" style="width: 180px;padding: 5px;" title="导航栏" split="true">
		<ul id="tree" class="easyui-tree">
		</ul>
	</div>
	<!-- 页脚 -->
	<div region="south" styke="height: 35px;padding: 5px;" align="center">
		版权所有 李凯132855455@qq.com
	</div>
	
	<div id="dlg" class="easyui-dialog" style="width: 400px;height: 220px;padding: 10px" 
		data-options="modal:true,closed:true,buttons:'#dlg-buttons',iconCls:'icon-modifyPassword'">
		<form id="fm" style="margin-top: 5px;margin-left: 50px;">
			<table>
				<tr>
					<td align="right">用户名：</td>
					<td><input type="text" id="username" name="username" readonly value="${user.username }"/></td>
				</tr>
				
				<tr>
					<td align="right">原密码：</td>
					<td><input type="text" id="password" name="password"/></td>
				</tr>
				
				<tr>
					<td align="right">新密码：</td>
					<td><input type="text" id="newPassword" name="newPassword"/></td>
				</tr>
				
				<tr>
					<td align="right">确认新密码：</td>
					<td><input type="text" id="confirmPassword" name="confirmPassword"/></td>
				</tr>
			</table>
		</form>
	</div>
	<div id="dlg-buttons">
		<a id="submitBtn" class="easyui-linkbutton" iconCls="icon-ok">确定</a>
	</div>
</body>
</html>